library(pracma)
###############################################################
##17
# A=matrix(c(1,2,3,4,5,6),nrow=2,byrow=T)
# B=matrix(c(7,8,9,0,1,2,3,4,5),nrow=3,byrow=T)
# print(A)
# print(B)
# C=A%*%B
# print(C)
# print(sum(sum(C)))

###############################################################
##18
# A=matrix(c(1,2,3,4),nrow=2,byrow=T)
# B=matrix(c(5,6,7,8),nrow=2,byrow=T)
# C=matrix(c(9,0,1,2),nrow=2,byrow=T)
# print(A)
# print(B)
# print(C)
# D=(A%*%B)%*%C
# print(D)
# print(sum(sum(D)))

###############################################################
##26
# A=matrix(c(1,2,3,0),nrow=2,byrow=T)
# B=A%*%A%*%A+2*A%*%A+3*A+4*eye(2)
# print(B)
# print(sum(sum(B)))

###############################################################
# ##31
# A=matrix(c(2,1,3,3,1,2,2,3,1),nrow=3,byrow=T)
# print(A)
# print(det(A))
# print('A inverse:')
# Ainv=inv(A)
# print(Ainv)
# print(sum(sum(Ainv)))
# 
# print('Astar:')
# Astar=det(A)*inv(A)
# print(Astar)
# print(sum(sum(Astar)))

a1=c(5,3,5,12)
a2=c(2,2,3,5)
a3=c(1,7,9,4)
A=matrix(c(a1,a2,a3),nrow=3,byrow=T)
print(A)
print(rref(A))
#print(Rank(A))


# x=c(3,2,5,1,7,4,6)
# y=c(1,7,2,4,3,6,5)
# s=0
# for (k in 1:(length(x)-1)){
#   for (m in (k+1):length(x)){
#     if (x[k]>x[m]) s=s+1
#     if (y[k]>y[m]) s=s+1
#   }
# }
# print(s)


